package com.realife.eson.common.util.common;

import com.realife.eson.common.asserts.AssertNP;
import org.apache.http.client.methods.HttpRequestBase;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2021/5/22 19:38
 * @description:
 */
public class ResourcesCloseUtils {
    private ResourcesCloseUtils() {

    }


    /**
     * 关闭资源通道
     *
     * @param args
     */
    public static void close(AutoCloseable... args) {
        for (AutoCloseable arg : args) {
            if (arg != null) {
                try {
                    arg.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * 释放连接
     *
     * @param requestBases
     */
    public static void close(HttpRequestBase... requestBases) {
        for (HttpRequestBase requestBase : requestBases) {
            if (AssertNP.legalParams(requestBase)) {
                requestBase.releaseConnection();
            }
        }
    }
}

